class node:
    def __init__(self, name, depth) -> None:
        self.name = name
        self.depth = depth

    def set_cost(self, cost):
        self.cost = cost
        
    def __str__(self) -> str:
        return '\t'*self.depth + "┗━" + self.name + f" {self.cost if self.cost != -1 else ''}"

def format(trace_info: str):
    i = 0
    lines = trace_info.split('\n')
    res = ""
    func_stk = []
    output_seq = []
    for line in lines:
        if line.find("Entering") != -1:
            func_node = node(line.replace("Entering", ""), i)
            output_seq.append(func_node)
            func_stk.append(func_node)
            # res += i * '\t' + "┗━" + line.replace("Entering function", "") + '\n'
            i += 1
        elif line.find("Leaving") != -1:
            func_node = func_stk.pop()
            if line.find("cost") != -1:
                func_node.set_cost(line[line.find("cost"):])
            else:
                func_node.set_cost(-1)
            # res += i * '\t' + line[line.find("cost"):] + '\n'
            i -= 1
            
    for item in output_seq:
        res += str(item) + '\n'
    return res

# tracing = "TRACE: Entering function void ProfileAction::FillMenuWinInfo(Json::Value&) (../operation/profileaction.cpp:24528)\nTRACE: Leaving function void ProfileAction::FillMenuWinInfo(Json::Value&) cost: 198\nTRACE: Entering function bool isSameMenuCh(std::__cxx11::string, int) (../operation/profileaction.cpp:2274)\nTRACE: Leaving function bool isSameMenuCh(std::__cxx11::string, int) cost: 728\nTRACE: Entering function void ProfileAction::HideMenu(bool) (../operation/profileaction.cpp:19979)\nTRACE: Entering function void ProfileAction::LeaveMenu(std::__cxx11::string, int, int) (../operation/profileaction.cpp:3352)\nTRACE: Entering function int Action::SendMsgToMouse(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:210)\nTRACE: Leaving function int Action::SendMsgToMouse(int, std::__cxx11::string, Json::Value&) cost: 1471\nTRACE: Leaving function void ProfileAction::LeaveMenu(std::__cxx11::string, int, int) cost: 2425\nTRACE: Leaving function void ProfileAction::HideMenu(bool) cost: 2490\nTRACE: Entering function int Action::SendMsgToClient(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:131)\nTRACE: Leaving function int Action::SendMsgToClient(int, std::__cxx11::string, Json::Value&) cost: 620\nTRACE: Entering function void ProfileAction::LeaveMenu(std::__cxx11::string, int, int) (../operation/profileaction.cpp:3352)\nTRACE: Entering function int Action::SendMsgToMouse(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:210)\nTRACE: Leaving function int Action::SendMsgToMouse(int, std::__cxx11::string, Json::Value&) cost: 1919\nTRACE: Leaving function void ProfileAction::LeaveMenu(std::__cxx11::string, int, int) cost: 3040\nTRACE: Entering function void Action::RemindUser(int, Json::Value&) (../operation/action.cpp:420)\nTRACE: Entering function int Action::SendMsgToWsServer(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:168)\nTRACE: Leaving function int Action::SendMsgToWsServer(int, std::__cxx11::string, Json::Value&) cost: 189\nTRACE: Leaving function void Action::RemindUser(int, Json::Value&) cost: 503\nTRACE: Entering function int Action::SendMsgToWsServer(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:168)\nTRACE: Leaving function int Action::SendMsgToWsServer(int, std::__cxx11::string, Json::Value&) cost: 171\nTRACE: Entering function int Action::SendMsgToWsServer(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:168)\nTRACE: Leaving function int Action::SendMsgToWsServer(int, std::__cxx11::string, Json::Value&) cost: 179\nTRACE: Entering function void ProfileAction::CancelOsdMenu(std::__cxx11::string, int, int) (../operation/profileaction.cpp:3508)\nTRACE: Entering function void ProfileAction::ShowOsdMenu(int, bool, int) (../operation/profileaction.cpp:3559)\nTRACE: Entering function int Action::SendMsgToClient(int, std::__cxx11::string, Json::Value&) (../operation/action.cpp:131)\nTRACE: Leaving function int Action::SendMsgToClient(int, std::__cxx11::string, Json::Value&) cost: 181\nTRACE: Leaving function void ProfileAction::ShowOsdMenu(int, bool, int) cost: 965\nTRACE: Leaving function void ProfileAction::CancelOsdMenu(std::__cxx11::string, int, int) cost: 1048\n"
# print(format(tracing))